<style>
    #febs-quest xm-select {
        min-height: 30px;
        line-height: 30px;
    }

</style>

<div class="layui-fluid layui-anim febs-anim" id="febs-quest" lay-title="满意度调查表">
    <div class="layui-row layui-col-space8 febs-container">
        <div class="layui-col-md12 layui-col-sm12 layui-col-xs12">
            <div class="layui-card" style="margin: 0 auto;">
                <div class="layui-card-header">满意度调查表</div>
                <div class="layui-card-body user-profile-card">

                    <button type="button" class="layui-btn layui-btn-normal layui-btn-radius" id="add-quest">添加调查表
                    </button>

                    <table lay-filter="questTable" lay-data="{id: 'questTable'}"></table>

                </div>
            </div>
        </div>
    </div>
</div>

<script type="text/html" id="user-option">
    <a lay-event="detail"><i
            class="layui-icon febs-edit-area febs-green">&#xe7a5;</i></a>

    <a lay-event="del"><i class="layui-icon febs-edit-area febs-red">&#xe7f9;</i></a>
</script>
<script data-th-inline="none" type="text/javascript">
    layui.use(['jquery', 'febs', 'form', 'table'], function () {
        let $ = layui.jquery,
            febs = layui.febs,
            table = layui.table,
            $view = $('#febs-quest'),
            $addQuest = $view.find('#add-quest'),
            tableIns

        $addQuest.on('click', function () {
            febs.modal.view('添加调查表', 'questionn/questAdd', {
                area: $(window).width() <= 750 ? '90%' : '650px',
                offset: '100px'
            });
        });

        initTable();

        function initTable() {
            tableIns = febs.table.init({
                elem: $view.find('table'),
                id: 'questTable',
                url: ctx + 'web/get/questionnaire',
                method: 'post',
                page: false,
                totalRow: true,
                parseData: function (res) { //res 即为原始返回的数据
                    return {
                        "code": 0, //解析接口状态
                        "msg": "", //解析提示文本
                        data: res.data //解析数据列表
                    };
                },
                cols: [[
                    {field: 'id', title: 'id',width: 60},
                    {field: 'deptId', title: '科室id'},
                    {field: 'deptName', title: '科室名称'},
                    {field: 'title', title: '标题'},
                    {title: '操作', toolbar: '#user-option', width: 120}
                ]]
            });
        }

        table.on('tool(questTable)', function (obj) {
            let data = obj.data,
                layEvent = obj.event;
            if (layEvent === 'del') {
                febs.modal.confirm('删除调查表', '确定删除该调查表？', function () {
                    febs.post(ctx + 'web/delete/questionnaire', {id:data.id}, function (data) {
                        febs.alert.success('删除调查表成功');
                        tableIns.reload();
                    });
                });
            }
            if (layEvent === 'detail') {
                febs.modal.view('调查表详情', 'questionn/questDetail/'+data.id, {
                    area: $(window).width() <= 750 ? '90%' : '650px',
                    offset: '100px'
                });
            }
        });

    })


</script>